﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace AppFabricSample.Data
{
    public static class CacheKeyFunctionMapping
    {
        public static String GetClassName(String key)
        {
            var objects = key.Split('^');
            return objects[0];
        }
        public static String GetFunctionName(String key)
        {
            var objects = key.Split('^');
            return objects[1];
        }
        public static object[] GetParameters(String key)
        {
            var objects = key.Split('^');
            List<object> splitValues = new List<object>(objects);
            object[] param = splitValues.Skip(2).ToArray<object>();
            return param;
        }

        public static object[] GetParameters(String key, MethodInfo Function)
        {
            var objects = key.Split('^');
            List<String> splitValues = new List<String>(objects);
            List<String> strParams = splitValues.Skip(2).ToList();

            ParameterInfo[] paramInfoArray = Function.GetParameters();

            List<Object> ObjParmList = new List<object>();

            if (strParams.Count > 0)
            {
                int i = 0;
                foreach (ParameterInfo Param in paramInfoArray)
                {
                    ObjParmList.Add(Convert.ChangeType(strParams[i++], Param.ParameterType));
                }
            }

            return ObjParmList.ToArray();


            //return param;
        }
        


    }
}
